register ucsb.appscale.protoBuff.jar
register /root/software/apache-cassandra-0.7.4-src/lib/commons-lang-2.4.jar
register /root/software/apache-cassandra-0.7.4-src/lib/libthrift-0.5.jar
register /root/appscale/AppServer_Java/appengine-java-sdk-repacked/lib/impl/appengine-api.jar
register /root/software/apache-cassandra-0.7.4-src/lib/google-collections-1.0.jar

/*
user {name, city, state, sex}
logAction {user, action, timespan, sourceIp}
query: select city, sex, avg(timespan) join logAction and WebUser where logAction.user==Webuser.user;
*/

rows = LOAD 'cassandra://logAction_10/Standard1' USING org.apache.cassandra.hadoop.pig.CassandraStorage() as (key:chararray, value:bytearray);
userRows = filter rows by key matches 'actionlogtests___WebUser.*' ;
userMap = foreach userRows generate ucsb.appscale.protoBuff.ParseWithKey(key, value);
users = foreach userMap generate $0#'name' as name, (long)$0#'key' as user, $0#'city' as city, $0#'sex' as sex;

rows = LOAD 'cassandra://logAction_10/Standard1' USING org.apache.cassandra.hadoop.pig.CassandraStorage();
-- $ is for indexing into last LOAD
logRows = filter rows by $0 matches 'actionlogtests___LogAction.*';
logsMap = foreach logRows generate ucsb.appscale.protoBuff.Parse($1);
-- # sign is for referencing field for a map structure of pig
logs = foreach logsMap generate (long)$0#'user' as user, (double)$0#'timespan' as timespan;

total = join users by user, logs by user;
results = foreach total generate users::name, users::city, users::sex, logs::timespan;
-- can user STORE instead of dump
dump results; 
